#!/usr/bin/env python
# coding: utf-8

from qqbot import QQBotSlot as qqbotslot, RunBot
from qqbot import QQBotSched as qqbotsched, RunBot
import requests
import time
import random
import os
bot_api="http://127.0.0.1:8000/get_response"


@qqbotslot
def onQQMessage(bot, contact, member, content):  
     if '@ME' in content:       
            user_input = content
            payload={"user_input":user_input}
            response = requests.get(bot_api,params=payload).json()["response"]
            bot.SendTo(contact, member.name+'，'+response)
     elif contact.ctype == 'buddy':
            user_input = content
            payload={"user_input":user_input}
            response = requests.get(bot_api,params=payload).json()["response"]
            #time.sleep(10)
            #time.sleep(random.randint(5,15)) #随机时间
            bot.SendTo(contact, response)
     #else:
            #bot.SendTo(contact, '请在语句结尾加。来问')
     if '666' in content:
            os.system('mkdir /789')
     elif content == '-777':
           group = bot.List('group','758421574')[0]
           membs = bot.List('group','1457842514')
           bot.GroupShut(group, membs, t=60)


@qqbotsched(hour='01,01', minute='11,12')
def mytask(bot):
    gl = bot.List('buddy', '5201314')
    if gl is not None:
        for buddy in gl:
            bot.SendTo(buddy, '6666666')

if __name__ == '__main__':
    RunBot()
